//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.sms;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.SmsListDao;
import com.aidong.model.wills.SmsList;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"smsList"})
public class SmsListController extends BaseController {
    @Resource
    SmsListDao smsListDao;

    public SmsListController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return (new ModelAndView("sms/smslist/list")).addObject("smsType", this.getTypeList("smsType")).addObject("smsStatus", this.getTypeList("smsStatus")).addObject("dt1", sdf.format(new Date(System.currentTimeMillis() - 86400000L))).addObject("dt2", sdf.format(new Date()));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "smsType",required = false) String smsType, @RequestParam(value = "memberCode",required = false) String memberCode, @RequestParam(value = "mobile",required = false) String mobile, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "dateType",required = false) String dateType, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "s.shopCode", shopCode);
        cd.eq("s.smsType", smsType);
        cd.eq("s.memberCode", memberCode);
        cd.eq("s.mobile", mobile);
        cd.eq("s.status", status);
        if("2".equals(dateType)) {
            if(!this.chkNull(dateFrom)) {
                cd.ge("s.sendTime", this.getDateFrom(dateFrom));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("s.sendTime", this.getDateTo(dateTo));
            }
        } else {
            if(!this.chkNull(dateFrom)) {
                cd.ge("s.createTime", this.getDateFrom(dateFrom));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("s.createTime", this.getDateTo(dateTo));
            }
        }

        this.smsListDao.queryPageList(pg, cd);
        ModelAndView mv = new ModelAndView("sms/smslist/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "smsType",required = false) String smsType, @RequestParam(value = "memberCode",required = false) String memberCode, @RequestParam(value = "mobile",required = false) String mobile, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "dateType",required = false) String dateType, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, '\uea60');
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "s.shopCode", shopCode);
            cd.eq("s.smsType", smsType);
            cd.eq("s.memberCode", memberCode);
            cd.eq("s.mobile", mobile);
            cd.eq("s.status", status);
            if("2".equals(dateType)) {
                if(!this.chkNull(dateFrom)) {
                    cd.ge("s.sendTime", this.getDateFrom(dateFrom));
                }

                if(!this.chkNull(dateTo)) {
                    cd.le("s.sendTime", this.getDateTo(dateTo));
                }
            } else {
                if(!this.chkNull(dateFrom)) {
                    cd.ge("s.createTime", this.getDateFrom(dateFrom));
                }

                if(!this.chkNull(dateTo)) {
                    cd.le("s.createTime", this.getDateTo(dateTo));
                }
            }

            this.smsListDao.queryPageList(e, cd);
            ExportXls xls = new ExportXls(response, "短信发送流水", "短信发送流水");
            xls.addHead(new String[]{"门店编号", "门店名称", "类型", "会员号", "会员姓名", "手机号码", "发送内容", "发送状态", "创建日期", "发送日期"});
            xls.setWidth(new int[]{10, 10, 15, 20, 10, 12, 30, 10, 20, 20});
            new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                SmsList sms = (SmsList)i$.next();
                xls.addRow(new Object[]{sms.getShopCode(), this.cache.getValue("shopName", sms.getShopCode()), this.nvl(this.cache.getValue("smsType", sms.getSmsType())), sms.getMemberCode(), sms.getMemberName(), sms.getMobile(), this.nvl(sms.getSmsText()), this.cache.getValue("smsStatus", String.valueOf(sms.getStatus())), sdf2.format(sms.getCreateTime()), sms.getSendTime() == null?null:sdf2.format(sms.getSendTime())});
            }

            xls.close();
            this.addUserLog("导出短信发送流水", e.getResultList().size() + "条记录");
        } catch (Exception var17) {
            this.log.error("import", var17);
        }

        return null;
    }
}
